/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.rehan.commons;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Martin Řehánek <rehan at mzk.cz>
 */
public class PidList {

    private final List<String> list;

    public PidList(File file) throws IOException {
        list = loadFromFile(file);
    }

    private List<String> loadFromFile(File file) throws IOException {
        LineNumberReader reader = new LineNumberReader(new FileReader(file));
        List<String> result = new ArrayList<String>();
        while (reader.ready()) {
            String line = reader.readLine();
            if (!line.startsWith("#") && !containsOnlyWhiteSpaces(line)) {
                result.add(line);
            }
        }
        return result;
    }

    private boolean containsOnlyWhiteSpaces(String line) {
        for (char character : line.toCharArray()) {
            if (!Character.isWhitespace(character)) {
                return false;
            }
        }
        return true;
    }

    public List<String> content() {
        return list;
    }
}
